{extend name="admin/b2c/base" /} {block name="resources"}
<script type="text/javascript" charset="utf-8"
	src="ADMIN_JS/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="ADMIN_JS/ueditor/ueditor.all.js"></script>
{/block} {block name="main"}
<div class="set-style">
	<dl>
		<dt>标题：</dt>
		<dd>
			<input id="title" type="text" value="{$document_detail.title}" />
		</dd>
	</dl>
	<dl>
		<dt>标题图片：</dt>
		<dd>
			<div class="class-logo">
				<p>
				{if condition="$document_detail.image !=''"}
					<img id="imglogo" src="__UPLOAD__/{$document_detail.image}">
				{else/}
					<img id="imglogo">
				{/if}
				</p>
			</div>
			<div class="ncsc-upload-btn">
				<a href="javascript:void(0);"><span> <input
						hidefocus="true" size="1" class="input-file" name="file_upload"
						id="uploadImg" type="file" onchange="imgUpload(this,'logo');">
						<input type="hidden" id="logo" value="{$document_detail.image}" /></span>
					<p>
						<i class="fa fa-cloud-upload text"></i>上传图片
					</p> </a>
			</div>
			<p class="hint">
				<br> <span style="color: orange;">建议使用宽100像素-高100像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>链接地址：</dt>
		<dd>
			<input id="link_url" type="text" value="{$document_detail.link_url}" />
		</dd>
	</dl>
	<dl>
		<dt>所属分类：</dt>
		<dd>
			<select id="class_id">
			{volist name="help_class_list" id="v"}
				<option value="{$v['class_id']}" {if condition="$document_detail.class_id == $v['class_id']"}{/if}>{$v['class_name']}</option>
				{/volist}
			</select>
		</dd>
	</dl>
	<dl>
		<dt>内容：</dt>
		<dd>
			<script id="editor" type="text/plain"
				style="width: 100%; height: 100px;"></script>
		</dd>
	</dl>
	<dl>
		<dt>排序：</dt>
		<dd>
			<input id="sort" type="text" value="{$document_detail.sort}" />
		</dd>
	</dl>
	<input type="hidden" value="{$id}" id="document_id" />
	<input type="hidden" value="{$document_detail.content}" id="content" />
	
	<button class="edit_button" onclick="setConfigAjax();">提交</button>
</div>
<script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
{include file="admin/b2c/openDialog" /}
<script>
var ue = UE.getEditor('editor');
$(function(){
	UE.getEditor('editor').addListener( 'ready', function() {
		UE.getEditor('editor').setContent($("#content").val());
	} );
})
	function setConfigAjax() {
		var id = $("#document_id").val();
		var title = $("#title").val();
		var class_id = $("#class_id").val();
		var link_url = $("#link_url").val();
		var image = $("#logo").val();
		var content = UE.getEditor('editor').getContent();
		var sort = $("#sort").val();
		if(title == ""){
			showMessage('error', "请输入标题");
			return;
		}
		if(content == ""){
			showMessage('error', "请输入内容");
			return;
		}
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Config/updateDocument",
			data : {
				'id' : id,
				'title' : title,
				'class_id' : class_id,
				'link_url' : link_url,
				'content' : content,
				'image' : image,
				'sort' : sort
			},
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"], 'ADMIN_MAIN/config/helpdocument');
				} else {
					showMessage('error', data["message"]);
				}
			}
		});
	}
	/**
	 *图片上传
	 */
	function imgUpload(event, obj) {
		var fileid = $(event).attr("id");
		fileCommonUpload("UPLOAD_URL", fileid, "__UPLOAD__", obj);
	}
</script>
{/block}
